<template>
  <div class="dashboard-editor-container">
    <PanelGroup @handleSetLineChartData="handleSetLineChartData"/>

    <div class="chart-line">
      <line-chart :chart-data="lineChartData" :yTitle="yTitle"/>
    </div>

    <el-row :gutter="20" class="chart-row">
      <el-col :xs="24" :sm="24" :lg="12">
        <el-card>
          <pie-chart />
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="12">
        <el-card>
          <pie-chart2/>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {getToken}  from "@/utils/auth";
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
// import BarChart from './components/BarChart'
import PieChart from './components/PieChart'

// import LineChart2 from './components/LineChart2'
// import BarChart2 from './components/BarChart2'
import PieChart2 from './components/PieChart2'


const yTitles = {
  purchases: '收益金额(万元)',
  shoppings: '广告数量(个)',
  newUsers: '最近七天页面访问量(人)',
  messages: '物品数量(条)',
}

export default {
  name: 'DashBoard',

  data() {
    return {
      newUsers:{
        actualData:[],
        expectedData:[100,80,50,120,100,50,80],
      },
      lineChartDatas:[],
      lineChartData: {},
      yTitle: yTitles.newUsers,
    }
  },
  
  mounted () {
    this.getData();
    setTimeout(() => {
      // alert(this.lineChartDatas)
      this.lineChartData = this.lineChartDatas[0]
    }, 1000);
  },

  methods: {
    //请求数据
    async getData(){
      const {data:{list}} = await this.$API.data.getData(getToken());
      // console.log(item);  
      // console.log(list);  
      // console.log(this.lineChartDatas.actualData);
      this.newUsers.actualData = list
      // alert(this.newUsers.actualData)
      this.lineChartDatas.push(this.newUsers)
      // console.log(this.lineChartDatas);
    }
  },

  components: {
    PanelGroup,
    LineChart,
    // BarChart,
    PieChart,
    // LineChart2,
    // BarChart2,
    PieChart2,
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(255, 255, 255);
  .chart-line {
    background:#fff;
    padding:0 0 0 0;
    margin-bottom:32px;
  }
  .chart-row {
    background: #fff;
    margin-bottom: 32px;
  }
}
</style>
